<?php
/**
 * @file All interactions with the variable table.
 */

class variable {
  /**
   * Get a single value from the variable table.
   */
  public static function get(string $name, $default) {
    global $config;
    $query = 'SELECT `id`,`value` FROM `variables` WHERE `id`=`$name`';
    /* execute query */
    
  }
  
  /**
   * Get all the values from the variable table.
   */
  public static function getAll($header = FALSE) {
    $query = 'SELECT `id`,`value` FROM `variables`';
    /* execute query // */ $result = array();
    global $config;
    /* Set the $config[$name] = variables*/
    if($header) {
      $header = array('id', 'value');
      $result = array_unshift($result, $header);
    }
    return $result;
  }
  
  /**
   * Insert a value into the variable table.
   */
  public static function set(string $name, $value) {
    global $config;
    $config[$name] = $value;
    if(is_array($value) || is_object($value)) {
      $value = serialize($value);
    }
    /**
     * REPLACE = update if exists, else insert; only possible due to the lack
     * of a `created_at` column.
     */
    $query = "REPLCAE `variables` (`id`, `value`) VALUES (`$name`, `$value`)";
    /* execute query */
  }
}